<?php
/**
 *      [Elitechmedia!] (C)2001-2099 MYSELF Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: adddh.php 22609 2013-10-16 01:55:33Z zhangchaofeng
 */
if(!isset($_SESSION)){
	session_start();
}
if(!$_SESSION['uid']){
	require_once "tmp/login.htm";exit;
}
include_once("classes/DB.class.php");
include_once("classes/page.class.php");
include_once("function/member.php");
include_once("function/util.func.php");
date_default_timezone_set('Asia/Shanghai');
$uid=$_SESSION['uid'];
$cid=$_SESSION['c_id'];
$id=addslashes($_REQUEST['id']);
if($id!=''):
$info = $GLOBALS["DB"]->result("SELECT id,c_name,c_address,c_tel,c_linkman,c_info FROM company where id='$id'");
$info=$info[0];
endif;
if($_SERVER['REQUEST_METHOD'] == 'POST'):
	$data['c_name']=addslashes($_POST['c_name']);
	$upid=$_POST['upid'];
	if($data['c_name']!=''):
		$data['c_address']=addslashes($_POST['c_address']);
		$data['c_tel']=addslashes($_POST['c_tel']);
		$data['c_linkman']=addslashes($_POST['c_linkman']);
		$data['c_info']=addslashes($_POST['c_info']);
		if($upid!=''):
			$GLOBALS["DB"]->execute_event("update company set ".implode_field_value($data) ." where id='$upid'");
			$message="<font color='green'>您的操作已经成功....</font>";
			$text="如果您的浏览器没有自动跳转，请点击这里";
			$url="main.php";
			include 'tmp/success.htm';exit;
		else:
			$fid = $GLOBALS["DB"]->insert("INSERT INTO company set ".implode_field_value($data));
			if(!$fid):
				$message="<font color='red'>对不起数据保存失败.!!</font>";
				$text="如果您的浏览器没有自动跳转，请点击这里";
				$url="main.php";
				include 'tmp/error.htm';exit;
			else:
				if($cid==-1):
					$data1['c_id']=$fid;
					$GLOBALS["DB"]->execute_event("update user set ".implode_field_value($data1) ." where uid='$uid'");
					$_SESSION=array();
					$userinfo = $GLOBALS["DB"]->result("SELECT uid,c_id,username FROM user where uid='$uid'");
					$userinfo=$userinfo[0];
					$_SESSION['c_id']=$userinfo['c_id'];
					$_SESSION['uid']=$userinfo['uid'];
					$_SESSION['username']=$userinfo['username'];
					$message="<font color='green'>企业已经新建成功,您可以进行您的企业管理..!</font>";
					$text="如果您的浏览器没有自动跳转，请点击这里";
					$url="main.php";
					include 'tmp/success.htm';exit;
				else:
					$message="<font color='green'>您的操作已经成功....</font>";
					$text="如果您的浏览器没有自动跳转，请点击这里";
					$url="main.php";
					include 'tmp/success.htm';exit;
				endif;
			endif;
		endif;
	else:
		$message="<font color='red'>标题不能为空...!!</font>";
		$text="如果您的浏览器没有自动跳转，请点击这里";
		$url="main.php";
		include 'tmp/error.htm';exit;
	endif;
endif;
include 'tmp/adddh.htm';